package it.patterns.behavioral.iterator;

public class ConcreteIterator<Item> implements Iterator<Object> {

	private Aggregate<Item> aggregate;
	private int current;

	public ConcreteIterator(Aggregate<Item> aggregate) {
		super();
		this.aggregate = aggregate;
		current = 0;
	}

	@Override
	public void first() {
		current = 0;
	}

	@Override
	public void next() {
		current++;
	}

	@Override
	public boolean isDone() {
		return (current >= aggregate.getSize());
	}

	@Override
	public Item currentItem() {
		try {
			return aggregate.get(current);
		} catch (Exception e) {
			return null;
		}
	}

}
